// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import utils from './utils/utils'
import store from './store'

Vue.config.productionTip = false
Vue.prototype.$utils = utils //定义$utils属性

// 路由前获取 openid
router.beforeEach((to, from, next) => {
if (localStorage.getItem('openId')) { // 判断是否有openId
			// 以获取openid后路由到登录页面
			console.log('已获取openId>>>',utils.getLocalStorage('openId'));
			next();
} else {
				console.log('获取Cookie值>>>',utils.getCookie('userInfo'));
				if(utils.getCookie('userInfo') != null){
					let userInfo = decodeURI(utils.getCookie('userInfo'));
					userInfo = JSON.parse(userInfo);
					if(userInfo.openId != '' && userInfo.openId != undefined && userInfo.openId != null){
						localStorage.openId = userInfo.openId;
						next();
					}
				}else{
					location.href = "http://tuxiaolong.tunnel.qydev.com/wx/getUserInfo?url="+location.href;
				}
		}
});
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
